<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>路径转换工具</title>
    <style>
      textarea {
        box-sizing: border-box;
        width: 100%;
        height: 150px;
        padding: 10px;
      }
    </style>
  </head>
  <body>
    <textarea
      id="inputPath"
      placeholder="请输入完整的文件路径，如 C:\\Users\\zhangg\\projects\\ongoing\\admin-in-one\\src\\views\\plat\\pay\\paysetting\\index.vue"
      oninput="convertAndCopy()"
    ></textarea>
    <script>
      function convertAndCopy() {
        var input = document.getElementById("inputPath").value;
        // 查找 "src/" 开始的部分，并截取该部分至字符串末尾
        var startIndex = input.indexOf("src\\");
        if (startIndex !== -1) {
          var pathSegment = input.substring(startIndex).replace(/\\/g, "/");
          navigator.clipboard
            .writeText(`npx eslint ${pathSegment}`)
            .then(() => console.log("路径已复制到剪贴板：" + pathSegment))
            .catch((err) => console.error("复制失败：", err));
        }
      }
    </script>
  </body>
</html>
